package com.kefu.call.controller;

import cn.hutool.core.thread.ThreadUtil;
import com.kefu.basic.util.ResponseUtil;
import com.kefu.call.model.CallCompany;
import com.kefu.call.model.CallGateway;
import com.kefu.call.service.CallNotifyService;
import com.kefu.call.vo.CallHangUpVo;
import com.kefu.call.vo.GatewayByRegionVo;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.sys.model.SysTenant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Api(tags = "呼叫事件通知")
@RestController
@RequestMapping("call/notify")
public class CtiNotifyController extends AbstractBaseController {
    @Autowired
    private CallNotifyService callNotifyService;


    @PostMapping("initCallCompany")
    @ApiOperation(value = "初始化呼叫租户信息")
    public Result<CallCompany> initCallCompany(@RequestBody SysTenant param) {
        logger.info("初始化呼叫租户信息:{}", param);
        return ResultGenerator.genSuccessResult(callNotifyService.initCallCompany(param));
    }

    @PostMapping("/hangUp")
    @ApiOperation(value = "挂机推送")
    public void hangUp(@RequestBody CallHangUpVo param, HttpServletResponse response) {
        ResponseUtil.responseSuccess(response);
        logger.info("call_notify_hangUp:{}", param);
        ThreadUtil.sleep(500);
        callNotifyService.hangUp(param);
    }

    @PostMapping("/pushData")
    @ApiOperation(value = "补推数据")
    public void pushData(@RequestBody CallHangUpVo param) {
        logger.info("call_notify_pushData:{}", param);
        callNotifyService.pushData(param.getId(),param.getCallType(),param.getTenantId());
    }

    @PostMapping("/gatewayRegion")
    @ApiOperation(value = "获取区域线路")
    public Result<CallGateway> gatewayRegion(@RequestBody GatewayByRegionVo vo) {
        logger.info("gatewayRegion:{}", vo);
        return ResultGenerator.genSuccessResult(callNotifyService.gatewayRegion(vo));
    }

}
